<template>
  <!--查询查复组件-->
  <el-dialog :title="winTitle" :visible.sync="dialogVisible" width="560px"
             :close-on-click-modal='false'>
    <!--提交部分-->
    <h2 slot="title">查询查复</h2>
    <button type="button" aria-label="Close" class="el-dialog__headerbtn" @click.stop="cancelModal">
      <i class="el-dialog__close el-icon el-icon-close"></i></button>
    <el-form label-width="80px" :model="formData" ref="formData" :rules="rules">
      <el-row>
        <el-col :span="24">
          <el-form-item label="查询查复原因：" prop="queryReason">
            <el-input type="textarea" v-model="formData.queryReason" style="width: 90%" rows="4" maxlength="64"
                      show-word-limit>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!--操作按钮-->
      <div class="opt-btn">
        <el-button type="primary" size="small" @click="commitData">提交</el-button>
        <el-button type="primary" size="small" @click="closeWin">关闭</el-button>
      </div>
    </el-form>
    <div>
      <!--查询查复历史列表部分-->
      <el-table
        :data="tableData"
        style="width: 100%">
          <el-table-column
            prop="date"
            label="日期"
            width="180"></el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            width="180"></el-table-column>
          <el-table-column
            prop="address"
            label="地址"></el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: "QueryAndReply",
    props: {
      dialogVisible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        clickTimes:1,
        winTitle: '',
        //作为属性： 已经是默认值了 不能重复注入数据值 ： 需要去掉
        // dialogVisible: true,
        formData: {},
        rules:{
          queryReason: [
            { required: true, message: '请输入原因' , trigger: 'blur' },
            { min: 1, max: 64, message: '长度在 1 到 100 个字', trigger: 'blur' }
          ],
        },
        tableData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }]
      }
    },
    methods:{
      initForm(){
        this.formData = {
          queryReason: '',
        };
        if(this.$refs.formData){
          this.$refs.formData.resetFields();
        }
      },
      closeWin(){
        this.formData.queryReason='';
        this.dialogVisible= false;
      },
      commitData() {
        const that = this;
        this.$refs['formData'].validate((valid) => {
          if (valid) {
            that.submitData();
          }
        })
      },
      submitData() {
        //防止重复提交
        if(this.clickTimes >1){
          this.message("任务已提交，正在处理中。。。");
          return false;
        }
        this.clickTimes++;
        const that = this;
        //关闭窗口
        that.dialogVisible = false
      },
      cancelModal(){
        // 关闭弹窗，触发父组件修改visible值
        this.$emit('update:dialogVisible', false);
      }
    }
  }
</script>

<style scoped>

</style>
